from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-15 14:08:57.599184
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 15, Feb, 2021
Time: 14:09:02
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.2038
Nobs: 203.000 HQIC: -47.0784
Log likelihood: 2336.37 FPE: 1.97851e-21
AIC: -47.6727 Det(Omega_mle): 1.28347e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.467635 0.139271 3.358 0.001
L1.Burgenland 0.083681 0.071700 1.167 0.243
L1.Kärnten -0.218256 0.060477 -3.609 0.000
L1.Niederösterreich 0.122176 0.166200 0.735 0.462
L1.Oberösterreich 0.240798 0.146094 1.648 0.099
L1.Salzburg 0.203145 0.077194 2.632 0.008
L1.Steiermark 0.104871 0.103858 1.010 0.313
L1.Tirol 0.146081 0.069515 2.101 0.036
L1.Vorarlberg -0.004193 0.063868 -0.066 0.948
L1.Wien -0.131573 0.137371 -0.958 0.338
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.479703 0.168992 2.839 0.005
L1.Burgenland 0.012825 0.087002 0.147 0.883
L1.Kärnten 0.359014 0.073383 4.892 0.000
L1.Niederösterreich 0.131107 0.201668 0.650 0.516
L1.Oberösterreich -0.142141 0.177272 -0.802 0.423
L1.Salzburg 0.198051 0.093667 2.114 0.034
L1.Steiermark 0.208969 0.126023 1.658 0.097
L1.Tirol 0.139320 0.084350 1.652 0.099
L1.Vorarlberg 0.166425 0.077498 2.147 0.032
L1.Wien -0.541089 0.166687 -3.246 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.313391 0.062025 5.053 0.000
L1.Burgenland 0.106469 0.031932 3.334 0.001
L1.Kärnten -0.019208 0.026934 -0.713 0.476
L1.Niederösterreich 0.079854 0.074019 1.079 0.281
L1.Oberösterreich 0.288727 0.065064 4.438 0.000
L1.Salzburg -0.002949 0.034379 -0.086 0.932
L1.Steiermark -0.018382 0.046254 -0.397 0.691
L1.Tirol 0.087193 0.030959 2.816 0.005
L1.Vorarlberg 0.108893 0.028444 3.828 0.000
L1.Wien 0.062008 0.061179 1.014 0.311
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.223362 0.070177 3.183 0.001
L1.Burgenland -0.008651 0.036129 -0.239 0.811
L1.Kärnten 0.024074 0.030474 0.790 0.430
L1.Niederösterreich 0.049523 0.083747 0.591 0.554
L1.Oberösterreich 0.374945 0.073616 5.093 0.000
L1.Salzburg 0.091417 0.038897 2.350 0.019
L1.Steiermark 0.182928 0.052334 3.495 0.000
L1.Tirol 0.039149 0.035028 1.118 0.264
L1.Vorarlberg 0.088831 0.032183 2.760 0.006
L1.Wien -0.067591 0.069220 -0.976 0.329
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.517865 0.140319 3.691 0.000
L1.Burgenland 0.059094 0.072240 0.818 0.413
L1.Kärnten 0.016146 0.060932 0.265 0.791
L1.Niederösterreich -0.027942 0.167451 -0.167 0.867
L1.Oberösterreich 0.139560 0.147194 0.948 0.343
L1.Salzburg 0.058469 0.077774 0.752 0.452
L1.Steiermark 0.127610 0.104640 1.220 0.223
L1.Tirol 0.212329 0.070038 3.032 0.002
L1.Vorarlberg 0.024968 0.064349 0.388 0.698
L1.Wien -0.118538 0.138405 -0.856 0.392
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163947 0.098614 1.663 0.096
L1.Burgenland -0.016634 0.050769 -0.328 0.743
L1.Kärnten -0.010450 0.042822 -0.244 0.807
L1.Niederösterreich 0.111025 0.117682 0.943 0.345
L1.Oberösterreich 0.384944 0.103446 3.721 0.000
L1.Salzburg -0.021085 0.054659 -0.386 0.700
L1.Steiermark -0.020804 0.073540 -0.283 0.777
L1.Tirol 0.187591 0.049222 3.811 0.000
L1.Vorarlberg 0.037077 0.045223 0.820 0.412
L1.Wien 0.192114 0.097269 1.975 0.048
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.231355 0.126612 1.827 0.068
L1.Burgenland 0.063478 0.065184 0.974 0.330
L1.Kärnten -0.039077 0.054980 -0.711 0.477
L1.Niederösterreich -0.026278 0.151094 -0.174 0.862
L1.Oberösterreich -0.091616 0.132816 -0.690 0.490
L1.Salzburg 0.037580 0.070178 0.536 0.592
L1.Steiermark 0.390707 0.094419 4.138 0.000
L1.Tirol 0.489227 0.063197 7.741 0.000
L1.Vorarlberg 0.165263 0.058063 2.846 0.004
L1.Wien -0.219246 0.124885 -1.756 0.079
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.081145 0.152934 0.531 0.596
L1.Burgenland 0.034824 0.078734 0.442 0.658
L1.Kärnten -0.082962 0.066410 -1.249 0.212
L1.Niederösterreich 0.242929 0.182505 1.331 0.183
L1.Oberösterreich -0.013148 0.160427 -0.082 0.935
L1.Salzburg 0.232878 0.084767 2.747 0.006
L1.Steiermark 0.142589 0.114047 1.250 0.211
L1.Tirol 0.068113 0.076335 0.892 0.372
L1.Vorarlberg 0.051116 0.070134 0.729 0.466
L1.Wien 0.248004 0.150848 1.644 0.100
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.586627 0.082516 7.109 0.000
L1.Burgenland -0.034097 0.042481 -0.803 0.422
L1.Kärnten -0.010820 0.035832 -0.302 0.763
L1.Niederösterreich -0.022746 0.098471 -0.231 0.817
L1.Oberösterreich 0.294895 0.086559 3.407 0.001
L1.Salzburg 0.019308 0.045736 0.422 0.673
L1.Steiermark 0.004418 0.061535 0.072 0.943
L1.Tirol 0.077254 0.041187 1.876 0.061
L1.Vorarlberg 0.128595 0.037841 3.398 0.001
L1.Wien -0.037594 0.081390 -0.462 0.644
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.137150 0.033386 0.197216 0.253114 0.064531 0.095819 -0.056818 0.168754
Kärnten 0.137150 1.000000 0.013336 0.191843 0.167143 -0.114354 0.155228 0.010678 0.319652
Niederösterreich 0.033386 0.013336 1.000000 0.309545 0.085380 0.214327 0.129309 0.048794 0.364597
Oberösterreich 0.197216 0.191843 0.309545 1.000000 0.302934 0.296801 0.106675 0.082250 0.132217
Salzburg 0.253114 0.167143 0.085380 0.302934 1.000000 0.152630 0.062650 0.089427 -0.008776
Steiermark 0.064531 -0.114354 0.214327 0.296801 0.152630 1.000000 0.102375 0.098964 -0.097038
Tirol 0.095819 0.155228 0.129309 0.106675 0.062650 0.102375 1.000000 0.157929 0.158883
Vorarlberg -0.056818 0.010678 0.048794 0.082250 0.089427 0.098964 0.157929 1.000000 0.046643
Wien 0.168754 0.319652 0.364597 0.132217 -0.008776 -0.097038 0.158883 0.046643 1.000000